package main

import (
	"core/env"
	"core/initial"
	"core/utils"
	"os"

	"github.com/fvbock/endless"
)

var (
	runMode string
)

func init() {
	args := os.Args
	if len(args) < 2 {
		runMode = env.RunModeAdminDev
	} else {
		switch args[1] {
		case "adminLocal":
			runMode = env.RunModeAdminLocal
		case "adminDev":
			runMode = env.RunModeAdminDev
		case "adminProd":
			runMode = env.RunModeAdminProd
		default:
			utils.Error("请输入正确的环境变量")
			os.Exit(1)
		}
	}
}

func main() {
	closeFunc, err := initial.Init(runMode)
	utils.Check("init.InitConf", err)
	defer closeFunc()

	//if strings.Contains(string(runMode), "prod") {
	//	gin.SetMode(gin.ReleaseMode)
	//}

	// 初始化路由
	router := InitRouter()

	addr := "localhost:" + env.Conf.ServerPORT
	utils.Info("start:", addr, runMode)
	err = endless.ListenAndServe(addr, router)
	utils.Check("ListenAndServe", err)
}
